package edu.csumb.itcd.teammario;
    import java.awt.*;

import javax.swing.*;

    
    public class Setup extends JFrame{

    
        private static Game gamePanel= null;
        private static boolean play = false;
        private static IntroPanel introPanel;
        private static JPanel setupPanel;
        private static boolean pause = false;
        private static boolean levelEnd = false;
        private static boolean shop = false;
        private static PauseMenu pausePanel = null;
        private static LevelEndMenu levelEndPanel;
        private static ShopMenu shopPanel;
        private static GameOverPanel gameOverPanel;
        private static boolean gameOver = false;
        
    
        //This makes the main window where the game will be run
        public Setup()
        {
            super("Team Mario Game");
            this.setResizable(false);
            setSize(800, 600);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setLayout(new BorderLayout());
            //creates a new game object
            
            setupPanel = new JPanel();
            setupPanel.setBackground(Color.white);
            setupPanel.setLayout(new BorderLayout());
            add(setupPanel);
            
            setupPanel.add(getPanel());
            gamePanel.setVisible(false);
            
            pausePanel = new PauseMenu();
            setupPanel.add(pausePanel, BorderLayout.CENTER);
            pausePanel.setVisible(false);
            
            levelEndPanel = new LevelEndMenu();
            setupPanel.add(levelEndPanel, BorderLayout.CENTER);
            levelEndPanel.setVisible(false);
            
            shopPanel = new ShopMenu();
            
            gameOverPanel = new GameOverPanel();
            setupPanel.add(gameOverPanel, BorderLayout.CENTER);
            gameOverPanel.setVisible(false);
            
            introPanel = new IntroPanel();
            setupPanel.add(introPanel, BorderLayout.CENTER);
            
//            LeaderBoard lb = new LeaderBoard();
//            try {
//				lb.readDataBase();
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
            
        }
        
        private static Game getPanel() {
            if  (gamePanel == null) {
                gamePanel = new Game();     
                gamePanel.setBackground(Color.white);
            }
            return gamePanel;
        }    
        
        public static boolean getPlay()
        {
        	return play;
        }
        
        public static void setPlay(boolean choice)
        {
        	play = choice;
        	if (play)
        	{
        		introPanel.setVisible(false);
        		pausePanel.setVisible(false);
        		levelEndPanel.setVisible(false);
        		gameOverPanel.setVisible(false);
        		gamePanel.setVisible(true);
        		gamePanel.reset();
        		pause = false;
        		levelEnd = false;
        	} else
        	{
        		gamePanel.setVisible(false);
        		pausePanel.setVisible(false);
        		levelEndPanel.setVisible(false);
        		gameOverPanel.setVisible(false);
        		introPanel.setVisible(true);
        	}
        }
        
        public static void setPause(boolean choice)
        {
        	pause = choice;
        	if (pause)
        	{
        		pausePanel.setVisible(true);
        		gamePanel.setVisible(false);
        	} else
        	{
        		pausePanel.setVisible(false);
        		gamePanel.setVisible(true);
        	}
        }
        
        public static boolean isPaused()
        {
        	return pause;
        }
        
        public static Game getGamePanel()
        {
        	return gamePanel;
        }
        
        public static void setLevelEnd(boolean choice)
        {
        	levelEnd = choice;
        	
        	if (levelEnd)
        	{
        		levelEndPanel.setVisible(true);
        		gamePanel.setVisible(false);
        	} else
        	{
        		levelEndPanel.setVisible(false);
        		gamePanel.setVisible(true);
        	}
        }
        
        public static void setShop(boolean choice)
        {
        	shop = choice;
        	
        	if (shop)
        	{
        		setupPanel.add(shopPanel);
        		shopPanel.updateShop();
        		levelEndPanel.setVisible(false);
        	} else
        	{
        		setupPanel.remove(shopPanel);
        		levelEndPanel.setVisible(true);
        	}
        }
        
        public static boolean isLevelEnded()
        {
        	return levelEnd;
        }
        
        public static void main(String[] args) {
            Setup window = new Setup();
            window.setVisible(true);
        }
        
        public static boolean isGameOver() {
			// TODO Auto-generated method stub
			return gameOver;
		}

		public static void setGameOver(boolean b) {
			// TODO Auto-generated method stub
			gameOver = b;
			
			if (gameOver)
			{
				gameOverPanel.setVisible(true);
				gamePanel.setVisible(false);
			} else
			{
				gameOverPanel.setVisible(false);
				gamePanel.setVisible(true);
			}
		}
    }

